package com.qf.service.impl;

import com.qf.dao.UserDao;
import com.qf.dao.impl.UserDaoImpl;
import com.qf.pojo.User;
import com.qf.service.AdminService;
import com.qf.utils.Constants;
import com.qf.utils.MD5Utils;

public class AdminServiceImpl implements AdminService {

    @Override
    public User login(String userName, String password) {
        UserDao userDao = new UserDaoImpl();
        User user= userDao.findByUserName(userName);
        if(user==null){
            return null;
        }
        if(Constants.ROLE_ADMIN !=user.getRole()){
            return null;
        }
        if(!Constants.USER_ACTIVE.equals(user.getStatus())){
            return null;
        }
        String md5PassWord = MD5Utils.md5(password);
        if(user.getPassword().equals(md5PassWord)){
            return user;
        }
        return null;
    }
}
